/**
 * Created by wxbing (wxbing000@163.com) on 2021/7/19.
 */
const xml2j = require('xml2js');
const fs = require('fs');

const parser = new xml2j.Parser({explicitArray: false, ignoreAttrs: true});

fs.readFile('./sbc.xml', function (err, data) {
    parser.parseString(data, function (err, result) {
        console.log(result.main.ipAddress);
        //
        result.main.ipAddress = '211.103.187.250';
        // result.main.
        // result.main.ipAddress
        // console.dir(result);
        console.log('Done');

        // convert JSON objec to XML
        const builder = new xml2j.Builder();
        const xml = builder.buildObject(result);

        // 写文件
        fs.writeFile('sbc.xml', xml, (err) => {
            if (err) {
                throw err;
            }

            console.log(`Updated XML is written to a new file.`);
        });
    });
});




